﻿
Imports xmlctrl
Imports xhtmlctrl
Imports webctrl

Public Class ie8accInstaller
    Inherits cacheControlProcessor

    Public Const _pathidentity As String = "/ie8accinst"
    Private info As ie8acceleratorInstallerInfo = Nothing

    Public Overrides Sub initial(Optional ByVal config As configParser = Nothing)
        MyBase.initial(config)
    End Sub

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    'to shared page, to avoid conflict on stringId, use individual stringsPackage
    Protected Overloads Overrides Function processImpl(ByVal context As httpContext _
                                                       , ByRef control As xmlcontrol) As Boolean
        assert(Not info Is Nothing, "info is nothing.")
        Try
            Dim strs As strings = Nothing
            strs = sp(context)
            Dim page As xhtmlpage = Nothing
            page = context.createControl(New xhtmlpage())
            page.title().text = strs(stringId.IE8ACCINSTALLER_TITLE_BEFORE) + info.name + _
                                strs(stringId.IE8ACCINSTALLER_TITLE_AFTER)

            Dim img As img = Nothing
            img = context.createControl(New img())
            img.src = staticrequest.generateStaticfileLinkUrl(ifoper(isemptystring(info.icon), "ie8acc.ico", info.icon))
            img.width = "32px"
            img.height = "32px"
            page.body().addchild(img)

            Dim label As label = Nothing
            label = context.createControl(New label())
            label.text = strs(stringId.IE8ACCINSTALLER_TITLETEXT_BEFORE) + info.name + _
                         strs(stringId.IE8ACCINSTALLER_TITLETEXT_AFTER)
            page.body().addchild(label)

            page.body().addchild(context.createControl(New br()))

            Dim emptyA As emptyA = Nothing
            emptyA = context.createControl(New emptyA())
            emptyA.text = strs(stringId.IE8ACCINSTALLER_CLICK_BEFORE) + info.name _
                            + strs(stringId.IE8ACCINSTALLER_CLICK_AFTER)
            emptyA.id = "id_ins"
            page.body().addchild(emptyA)

            Dim disableAction As String = Nothing
            changeInnerHtmlAndDisableById.invoke(page.inlineScript(), "'id_ins'", _
                                                 "'" + strs(stringId.IE8ACCINSTALLER_INSTALLED) + info.name + "'", _
                                                 disableAction)
            disableAction += ";"
            Dim installAction As String = Nothing
            ie8acceleratorInstaller.invoke(page.inlineScript() _
                                           , "'" _
                                             + ifoper(isemptystring(info.acc), _
                                                      staticrequest.generateStaticfileLinkUrl(info.filename), _
                                                      info.acc) _
                                             + "'" _
                                           , installAction)
            Dim actionTarget As String = Nothing
            ie8acceleratorInstalled.invoke(page.inlineScript() _
                                           , actionTarget _
                                           , disableAction _
                                           , "'" + strleft(context.url().full() _
                                                   , strlen(context.url().full()) _
                                                   - strlen(context.url().pathquery())) + "'" _
                                           , "'" + info.category + "'", installAction)
            page.body().onload += actionTarget + ";"
            emptyA.onclick() = installAction

            control = page
            Return True
        Catch ex As Exception
            raiseError("caught unexpected error, " + ex.Message, errorHandle.errorType.exclamation)
            Return False
        End Try
    End Function

    Public Sub New(ByVal inputInfo As ie8acceleratorInstallerInfo)
        MyBase.new()
        copy(info, inputInfo)
    End Sub
End Class
